{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# UFL, the 'Unified Form Language'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "UFL is part of FEniCS, where it is used to describe finite element problems that are to be solved using the framework. The appearance of the following code snippet should look sufficiently familiar, and it should be readily apparent how language such as this could be taken in and processed using the tools that we have seen:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#clear\n",
    "from dolfin import *\n",
    "\n",
    "\n",
    "\n",
    "# Create mesh and define function space\n",
    "\n",
    "mesh = UnitSquareMesh(8, 8)\n",
    "\n",
    "V = FunctionSpace(mesh, \"Lagrange\", 1)\n",
    "\n",
    "\n",
    "\n",
    "# Define boundary condition\n",
    "\n",
    "u0 = Function(V)\n",
    "\n",
    "bc = DirichletBC(V, u0, \"x[0] < DOLFIN_EPS || x[0] > 1.0 - DOLFIN_EPS\")\n",
    "\n",
    "\n",
    "\n",
    "# Define variational problem\n",
    "\n",
    "u = TrialFunction(V)\n",
    "\n",
    "v = TestFunction(V)\n",
    "\n",
    "f = Expression(\"10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)\",\n",
    "\n",
    "               degree=1)\n",
    "\n",
    "g = Expression(\"sin(5*x[0])\", degree=1)\n",
    "\n",
    "a = inner(grad(u), grad(v))*dx()\n",
    "\n",
    "L = f*v*dx() + g*v*ds()"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 0
}